/******************************************************************************
 Copyright (c) 2025 Qualcomm Technologies International, Ltd.
 All Rights Reserved.
 Qualcomm Technologies International, Ltd. Confidential and Proprietary.

 REVISION:      $Revision: #1 $
******************************************************************************/

#include "csr_bt_gatt_lib.h"
#include "gatt_battery_server.h"
#include "gatt_battery_server_access.h"
#include "gatt_battery_server_private.h"
#include "gatt_battery_server_db.h"
#include "csr_log_text_2.h"

#ifndef EXCLUDE_GATT_BATTERY_SERVICE_V1P1

/******************************************************************************/
bool GattBatteryServerSendBatteryLevelStatusIndication(const GBASS* batteryServer, uint16 numberCids, const uint32* cids, BatteryLevelStatus batteryLevelStatus)
{
    bool result = FALSE;
    uint16 index = 0;
    CSR_UNUSED(batteryServer);
    if ((batteryServer != NULL)  && numberCids)
    {
        if (batteryServer->indicationsEnabled)
        {
            result = TRUE;
            for (index = 0; index < numberCids; index++)
            {
                if (cids[index] == 0)
                {
                    /* CID must be non-zero */
                    result = FALSE;
                }
                else
                {
                    uint8* value = (uint8*)CsrPmemAlloc(GATT_BATTERY_LEVEL_STATUS_OCTET_SIZE);
                    uint8* temp = value;
                    uint16 size = 3;
                    SynMemCpyS(temp, GATT_BATTERY_LEVEL_STATUS_OCTET_SIZE, &batteryLevelStatus.flags, GATT_BATTERY_FLAGS_SIZE);
                    temp += GATT_BATTERY_FLAGS_SIZE;
                    SynMemCpyS(temp, GATT_BATTERY_LEVEL_STATUS_OCTET_SIZE, &batteryLevelStatus.powerState, GATT_BATTERY_LEVEL_STATUS_POWER_STATE_SIZE);
                    temp += GATT_BATTERY_LEVEL_STATUS_POWER_STATE_SIZE;
                    if (batteryLevelStatus.flags & IDENTIFIER_PRESENT)
                    {
                        SynMemCpyS(temp, GATT_BATTERY_LEVEL_STATUS_OCTET_SIZE, &batteryLevelStatus.identifier, GATT_BATTERY_LEVEL_STATUS_IDENTIFIER_OCTET_SIZE);
                        temp += GATT_BATTERY_LEVEL_STATUS_IDENTIFIER_OCTET_SIZE;
                        size += GATT_BATTERY_LEVEL_STATUS_IDENTIFIER_OCTET_SIZE;
                    }
                    if (batteryLevelStatus.flags & BATTERY_LEVEL_PRESENT)
                    {

                        SynMemCpyS(temp, GATT_BATTERY_LEVEL_STATUS_OCTET_SIZE, &batteryLevelStatus.batteryLevel, GATT_BATTERY_LEVEL_OCTET_SIZE);
                        temp += GATT_BATTERY_LEVEL_OCTET_SIZE;
                        size += GATT_BATTERY_LEVEL_OCTET_SIZE;
                    }
                    if (batteryLevelStatus.flags & ADDITIONAL_STATUS_PRESENT)
                    {

                        SynMemCpyS(temp, GATT_BATTERY_LEVEL_STATUS_OCTET_SIZE, &batteryLevelStatus.additionalStatus, GATT_BATTERY_LEVEL_STATUS_ADDITIONAL_STATUS_OCTET_SIZE);
                        temp += GATT_BATTERY_LEVEL_STATUS_ADDITIONAL_STATUS_OCTET_SIZE;
                        size += GATT_BATTERY_LEVEL_STATUS_ADDITIONAL_STATUS_OCTET_SIZE;
                    }
                    CsrBtGattIndicationEventReqSend(batteryServer->gattId, cids[index], HANDLE_BATTERY_LEVEL_STATUS, size, value);
                }
            }
        }
        else
        {
            result = FALSE;
        }
    }
    return result;
}

/******************************************************************************/
bool GattBatteryServerSendEstimatedServiceDateIndication(const GBASS *batteryServer, uint16 numberCids, const uint32 *cids, uint32 estimatedServiceDate)
{
	bool result = FALSE;
	uint16 index = 0;
	CSR_UNUSED(batteryServer);
	if((batteryServer != NULL) && (estimatedServiceDate <= 16777214) && numberCids)
	{
		if(batteryServer->indicationsEnabled)
		{
	        result = TRUE;
            for (index = 0; index < numberCids; index++)
            {
                if (cids[index] == 0)
                {
                    /* CID must be non-zero */
                    result = FALSE;
                }
                else
                {
                    /* Send Indication */
                    uint8* value = (uint8*)CsrPmemAlloc(GATT_ESTIMATED_SERVICE_DATE_OCTET_SIZE);
                    SynMemCpyS(value, GATT_ESTIMATED_SERVICE_DATE_OCTET_SIZE, &estimatedServiceDate, GATT_ESTIMATED_SERVICE_DATE_OCTET_SIZE);
                    CsrBtGattIndicationEventReqSend(batteryServer->gattId, cids[index], HANDLE_ESTIMATED_SERVICE_DATE, GATT_ESTIMATED_SERVICE_DATE_OCTET_SIZE, value);
                }
            }
        }
        else
        {
            result = FALSE;
        }
    }
    return result;
}

/******************************************************************************/
bool GattBatteryServerSendBatteryCriticalStatusIndication(const GBASS* batteryServer, uint16 numberCids, const uint32* cids, uint8 batteryCriticalStatus)
{
    bool result = FALSE;
    uint16 index = 0;
    CSR_UNUSED(batteryServer);
    if ((batteryServer != NULL) && (batteryCriticalStatus < 4) && numberCids)
    {
        if (batteryServer->indicationsEnabled)
        {
            result = TRUE;
            for (index = 0; index < numberCids; index++)
            {
                if (cids[index] == 0)
                {
                    /* CID must be non-zero */
                    result = FALSE;
                }
                else
                {
                    /* Send Indication */
                    uint8* value = (uint8*)CsrPmemAlloc(GATT_BATTERY_CRITICAL_STATUS_OCTET_SIZE);
                    SynMemCpyS(value, GATT_BATTERY_CRITICAL_STATUS_OCTET_SIZE, &batteryCriticalStatus, GATT_BATTERY_CRITICAL_STATUS_OCTET_SIZE);
                    CsrBtGattIndicationEventReqSend(batteryServer->gattId, cids[index], HANDLE_BATTERY_CRITICAL_STATUS, GATT_BATTERY_CRITICAL_STATUS_OCTET_SIZE, value);
                }
            }
        }
        else
        {
            result = FALSE;
        }
    }
    return result;
}

/******************************************************************************/
bool GattBatteryServerSendBatteryEnergyStatusIndication(const GBASS* batteryServer, uint16 numberCids, const uint32* cids, BatteryEnergyStatus batteryEnergyStatus)
{
    bool result = FALSE;
    uint16 index = 0;
    CSR_UNUSED(batteryServer);
    if ((batteryServer != NULL) && (batteryEnergyStatus.flags  < 64) && numberCids)
    {
        if (batteryServer->indicationsEnabled)
        {
            result = TRUE;
            for (index = 0; index < numberCids; index++)
            {
                if (cids[index] == 0)
                {
                    /* CID must be non-zero */
                    result = FALSE;
                }
                else
                {
                    /* Send Indication */
                    uint8* value = (uint8*)CsrPmemAlloc(GATT_BATTERY_ENERGY_STATUS_OCTET_SIZE);
                    uint8* octate = value;
                    uint16 size = 1;
                    SynMemCpyS(octate, GATT_BATTERY_ENERGY_STATUS_OCTET_SIZE, &batteryEnergyStatus, GATT_BATTERY_FLAGS_SIZE);
                    octate += GATT_BATTERY_FLAGS_SIZE;
                    if (batteryEnergyStatus.flags & EXTERNAL_SOURCE_POWER_PRESENT) 
                    {
                        SynMemCpyS(octate, GATT_BATTERY_ENERGY_STATUS_OCTET_SIZE, &batteryEnergyStatus.externalSourcePower, GATT_BATTERY_ENERGY_STATUS_FIELDS_OCTET_SIZE);
                        octate += GATT_BATTERY_ENERGY_STATUS_FIELDS_OCTET_SIZE;
                        size += GATT_BATTERY_ENERGY_STATUS_FIELDS_OCTET_SIZE;
                    }
                    if (batteryEnergyStatus.flags & PRESENT_VOLTAGE_PRESENT) 
                    {
                        SynMemCpyS(octate, GATT_BATTERY_ENERGY_STATUS_OCTET_SIZE , &batteryEnergyStatus.presentVoltage, GATT_BATTERY_ENERGY_STATUS_FIELDS_OCTET_SIZE);
                        octate += GATT_BATTERY_ENERGY_STATUS_FIELDS_OCTET_SIZE;
                        size += GATT_BATTERY_ENERGY_STATUS_FIELDS_OCTET_SIZE;
                    }
                    if (batteryEnergyStatus.flags & AVAILABLE_ENERGY_PRESENT) 
                    {
                        SynMemCpyS(octate, GATT_BATTERY_ENERGY_STATUS_OCTET_SIZE, &batteryEnergyStatus.availableEnergy, GATT_BATTERY_ENERGY_STATUS_FIELDS_OCTET_SIZE);
                        octate += GATT_BATTERY_ENERGY_STATUS_FIELDS_OCTET_SIZE;
                        size += GATT_BATTERY_ENERGY_STATUS_FIELDS_OCTET_SIZE;
                    }
                    if (batteryEnergyStatus.flags & AVAILABLE_BATTERY_CAPACITY_PRESENT) 
                    {
                        SynMemCpyS(octate, GATT_BATTERY_ENERGY_STATUS_OCTET_SIZE, &batteryEnergyStatus.availableBatteryCapacity, GATT_BATTERY_ENERGY_STATUS_FIELDS_OCTET_SIZE);
                        octate += GATT_BATTERY_ENERGY_STATUS_FIELDS_OCTET_SIZE;
                        size += GATT_BATTERY_ENERGY_STATUS_FIELDS_OCTET_SIZE;
                    }
                    if (batteryEnergyStatus.flags & CHARGE_RATE_PRESENT) 
                    {
                        SynMemCpyS(octate, GATT_BATTERY_ENERGY_STATUS_OCTET_SIZE, &batteryEnergyStatus.chargeRate, GATT_BATTERY_ENERGY_STATUS_FIELDS_OCTET_SIZE);
                        octate += GATT_BATTERY_ENERGY_STATUS_FIELDS_OCTET_SIZE;
                        size += GATT_BATTERY_ENERGY_STATUS_FIELDS_OCTET_SIZE;
                    }
                    if (batteryEnergyStatus.flags & AVAILABLE_ENERGY_AT_LAST_CHARGE_PRESENT) 
                    {
                        SynMemCpyS(octate, GATT_BATTERY_ENERGY_STATUS_OCTET_SIZE, &batteryEnergyStatus.availableEnergyAtLastCharge, GATT_BATTERY_ENERGY_STATUS_FIELDS_OCTET_SIZE);
                        octate += GATT_BATTERY_ENERGY_STATUS_FIELDS_OCTET_SIZE;
                        size += GATT_BATTERY_ENERGY_STATUS_FIELDS_OCTET_SIZE;
                    }
                    octate = NULL;
                    CsrBtGattIndicationEventReqSend(batteryServer->gattId, cids[index], HANDLE_BATTERY_ENERGY_STATUS, size, value);
                }
            }
        }
        else
        {
            result = FALSE;
        }
    }
    return result;
}

/****************************************************************************/
bool GattBatteryServerSendBatteryTimeStatusIndication(const GBASS* batteryServer, uint16 numberCids, const uint32* cids, GattBatteryTimeStatus currentBatteryTimeStatus)
{
    bool result = FALSE;
    uint16 index = 0;
    CSR_UNUSED(currentBatteryTimeStatus);
    if (batteryServer != NULL)
    {
        if (batteryServer->indicationsEnabled)
        {
            result = TRUE;
            for (index = 0; index < numberCids; index++)
            {
                if (cids[index] == 0)
                {
                    /* CID must be non-zero */
                    result = FALSE;
                }
                else
                {
                    /* Send indication */
                    /*
                        The battery time status inclued the the bit masking flags(mandatory) - 1 octet,
                        Estimated time in minutes until discharged(mandatory) - 3 octets,
                        Estimated time in minutes until discharged assuming for the remaining time the device is in standby(present if bit 0 of flags is set to 1) - 0 or 3 octets,
                        Estimated time in minutes until recharged(present if bit 1 of flags is set to 1) - 0 or 3 octets.
                    */
                    uint8* value = (uint8*)CsrPmemAlloc(sizeof(GattBatteryTimeStatus));
                    uint8* temp = value, size_value = 4;
                    SynMemCpyS(temp, sizeof(GattBatteryTimeStatus), &currentBatteryTimeStatus.batteryTimeStatusFlags, sizeof(uint8));
                    temp++;
                    SynMemCpyS(temp, sizeof(GattBatteryTimeStatus), &currentBatteryTimeStatus.timeUntilDischarged, 3 * sizeof(uint8));
                    temp += 3;
                    if (currentBatteryTimeStatus.batteryTimeStatusFlags & TIME_UNTIL_DISCHARGED_ON_STANDBY_PRESENT) 
                    {
                        size_value += 3;
                        SynMemCpyS(temp, sizeof(GattBatteryTimeStatus), &currentBatteryTimeStatus.timeUntilDischargedOnStandby, 3 * sizeof(uint8));
                        temp += 3;
                    }
                    if (currentBatteryTimeStatus.batteryTimeStatusFlags & TIME_UNTIL_RECHARGED_PRESENT) 
                    {
                        size_value += 3;
                        SynMemCpyS(temp, sizeof(GattBatteryTimeStatus), &currentBatteryTimeStatus.timeUntilRecharged, 3 * sizeof(uint8));
                        temp += 3;
                    }
                    CSR_LOG_TEXT_INFO((CsrBtGattLto, 0, "time_until_discharged = %d.", currentBatteryTimeStatus.timeUntilRecharged));
                    CsrBtGattIndicationEventReqSend(batteryServer->gattId, cids[index], HANDLE_BATTERY_TIME_STATUS, size_value, value);
                }
            }
        }
        else
        {
            result = FALSE;
        }
    }
    return result;
}

/****************************************************************************/
bool GattBatteryServerSendBatteryHealthStatusIndication(const GBASS* batteryServer, uint16 numberCids, const uint32* cids, GattBatteryHealthStatus batteryHealthStatus)
{
    bool result = FALSE;
    uint16 index = 0;
    CSR_UNUSED(batteryHealthStatus);
    if (batteryServer != NULL)
    {
        if (batteryServer->indicationsEnabled)
        {
            result = TRUE;
            for (index = 0; index < numberCids; index++)
            {
                if (cids[index] == 0)
                {
                    /* CID must be non-zero */
                    result = FALSE;
                }
                else
                {
                    /* Send indication */
                    /*
                        The battery health status inclued the the bit masking flags(mandatory) - 1 octet,
                        Battery health summary(present if bit 0 of flags is set to 1) - 0 or 1 octet,
                        Cycle count(present if bit 1 of flags is set to 1) - 0 or 2 octets,
                        Current Temperature(present if bit 2 of flags is set to 1) - 0 or 1 octet,
                        Deep Discharge Count(present if bit 3 of flags is set to 1) - 0 or 2 octets.
                    */
                    GattBatteryHealthStatus* value = (GattBatteryHealthStatus*)CsrPmemAlloc(sizeof(GattBatteryHealthStatus));
                    uint8* temp = (uint8*)value;
                    uint16  sizeValue = 1;
                    SynMemCpyS(temp, sizeof(GattBatteryHealthStatus), &batteryHealthStatus.batteryHealthStatusFlags, sizeof(uint8));
                    temp += 1;
                    if (batteryHealthStatus.batteryHealthStatusFlags & BATTERY_HEALTH_SUMMARY_PRESENT) 
                    {
                        sizeValue += 1;
                        SynMemCpyS(temp, sizeof(GattBatteryHealthStatus), &batteryHealthStatus.batteryHealthSummary, sizeof(uint8));
                        temp += 1;
                    }
                    if (batteryHealthStatus.batteryHealthStatusFlags & CYCLE_COUNT_PRESENT) 
                    {
                        sizeValue += 2;
                        SynMemCpyS(temp, sizeof(GattBatteryHealthStatus), &batteryHealthStatus.cycleCount, sizeof(uint16));
                        temp += 2;
                    }
                    if (batteryHealthStatus.batteryHealthStatusFlags & CURRENT_TEMPERATURE_PRESENT) 
                    {
                        sizeValue += 1;
                        SynMemCpyS(temp, sizeof(GattBatteryHealthStatus), &batteryHealthStatus.currentTemperature, sizeof(int8));
                        temp += 1;
                    }
                    if (batteryHealthStatus.batteryHealthStatusFlags & DEEP_DISCHARGE_COUNT_PRESENT) 
                    {
                        sizeValue += 2;
                        SynMemCpyS(temp, sizeof(GattBatteryHealthStatus), &batteryHealthStatus.deepDischargeCount, sizeof(uint16));
                        temp += 2;
                    }
                    CsrBtGattIndicationEventReqSend(batteryServer->gattId, cids[index], HANDLE_BATTERY_HEALTH_STATUS, sizeValue, (uint8*)value);
                }
            }
        }
        else
        {
            result = FALSE;
        }
    }
    return result;
}

/****************************************************************************/
bool GattBatteryServerSendBatteryHealthInformationIndication(const GBASS* batteryServer, uint16 numberCids, const uint32* cids, GattBatteryHealthInformation batteryHealthInformation)
{
    bool result = FALSE;
    uint16 index = 0;
    CSR_UNUSED(batteryHealthInformation);
    if (batteryServer != NULL)
    {
        if (batteryServer->indicationsEnabled)
        {
            result = TRUE;
            for (index = 0; index < numberCids; index++)
            {
                if (cids[index] == 0)
                {
                    /* CID must be non-zero */
                    result = FALSE;
                }
                else
                {
                    /* Send indication */
                    /*
                        The battery health information inclued the the bit masking flags(mandatory) - 1 octet,
                        Cycle count designed lifetime(present if bit 0 of flags is set to 1) - 0 or 2 octets,
                        Min designed operating temperature(present if bit 1 of flags is set to 1) - 0 or 1 octet,
                        Max designed operating temperature(present if bit 1 of flags is set to 1) - 0 or 1 octet.
                    */
                    GattBatteryHealthInformation* value = (GattBatteryHealthInformation*)CsrPmemAlloc(sizeof(GattBatteryHealthInformation));
                    uint8* temp = (uint8*)value;
					uint16 sizeValue = 1;
                    SynMemCpyS(temp, sizeof(GattBatteryHealthInformation), &batteryHealthInformation.batteryHealthInformationFlags, sizeof(uint8));
                    temp += 1;
                    if (batteryHealthInformation.batteryHealthInformationFlags & CYCLE_COUNT_DESIGNED_LIFETIME_PRESENT) 
                    {
                        sizeValue += 2;
                        SynMemCpyS(temp, sizeof(GattBatteryHealthInformation), &batteryHealthInformation.cycleCountDesignedLifetime, 2 * sizeof(uint8));
                        temp += 2;
                    }
                    if (batteryHealthInformation.batteryHealthInformationFlags & MIN_AND_MAX_OPERATING_TEMPERATURE_PRESENT) 
                    {
                        sizeValue += 1;
                        SynMemCpyS(temp, sizeof(GattBatteryHealthInformation), &batteryHealthInformation.minDesignedOperatingTemperature, sizeof(uint8));
                        temp += 1;
                        sizeValue += 1;
                        SynMemCpyS(temp, sizeof(GattBatteryHealthInformation), &batteryHealthInformation.maxDesignedOperatingTemperature, sizeof(uint8));
                        temp += 1;
                    }
                    CsrBtGattIndicationEventReqSend(batteryServer->gattId, cids[index], HANDLE_BATTERY_HEALTH_INFORMATION, sizeValue, (uint8*)value);
                }
            }
        }
        else
        {
            result = FALSE;
        }
    }
    return result;
}

/****************************************************************************/
bool GattBatteryServerSendBatteryInformationIndication(const GBASS* batteryServer, uint16 numberCids, const uint32* cids, GattBatteryInformation batteryInformation)
{
    bool result = FALSE;
    uint16 index = 0;
    CSR_UNUSED(batteryInformation);
    if (batteryServer != NULL)
    {
        if (batteryServer->indicationsEnabled)
        {
            result = TRUE;
            for (index = 0; index < numberCids; index++)
            {
                if (cids[index] == 0)
                {
                    /* CID must be non-zero */
                    result = FALSE;
                }
                else
                {
                    /* Send indication */
                    /*
                        The battery information inclued the the bit masking flags(mandatory) - 2 octets,
                        Battery features(mandatory) - 1 octet,
                        Battery manufacture date(present if bit 0 of flags is set to 1) - 0 or 3 octets,
                        Battery expiration date(present if bit 1 of flags is set to 1) - 0 or 3 octets,
                        Battery designed capacity(present if bit 2 of flags is set to 1) - 0 or 2 octets,
                        Battery low energy(present if bit 3 of flags is set to 1) - 0 or 2 octets,
                        Battery critical energy(present if bit 4 of flags is set to 1) - 0 or 2 octets,
                        Battery chemistry(present if bit 5 of flags is set to 1) - 0 or 1 octet1,
                        Nominal voltage(present if bit 6 of flags is set to 1) - 0 or 2 octets,
                        Battery aggregation group(present if bit 7 of flags is set to 1) - 0 or 1 octet.
                    */
                    GattBatteryInformation* value = (GattBatteryInformation*)CsrPmemAlloc(sizeof(GattBatteryInformation));
                    uint8* temp = (uint8*)value;
					uint16 sizeValue = 2;
                    SynMemCpyS(temp, sizeof(GattBatteryInformation), &batteryInformation.batteryInformationFlags, sizeof(uint16));
                    temp += 2;
                    SynMemCpyS(temp, sizeof(GattBatteryInformation), &batteryInformation.batteryFeatures, sizeof(uint8)); sizeValue += 1;
                    temp += 1;
                    if (batteryInformation.batteryInformationFlags & BATTERY_MANUFACTURE_DATE_PRESENT) 
                    {
                        sizeValue += 3;
                        SynMemCpyS(temp, sizeof(GattBatteryInformation), &batteryInformation.batteryManufactureDate, 3 * sizeof(uint8));
                        temp += 3;
                    }
                    if (batteryInformation.batteryInformationFlags & BATTERY_EXPIRATION_DATE_PRESENT) 
                    {
                        sizeValue += 3;
                        SynMemCpyS(temp, sizeof(GattBatteryInformation), &batteryInformation.batteryExpirationDate, 3 * sizeof(uint8));
                        temp += 3;
                    }
                    if (batteryInformation.batteryInformationFlags & BATTERY_DESIGNED_CAPACITY_PRESENT) 
                    {
                        sizeValue += 2;
                        SynMemCpyS(temp, sizeof(GattBatteryInformation), &batteryInformation.batteryDesignedCapacity, 2 * sizeof(uint8));
                        temp += 2;
                    }
                    if (batteryInformation.batteryInformationFlags & BATTERY_LOW_ENERGY_PRESENT) 
                    {
                        sizeValue += 2;
                        SynMemCpyS(temp, sizeof(GattBatteryInformation), &batteryInformation.batteryLowEnergy, 2 * sizeof(uint8));
                        temp += 2;
                    }
                    if (batteryInformation.batteryInformationFlags & BATTERY_CRTICAL_ENERGY_PRESENT) 
                    {
                        sizeValue += 2;
                        SynMemCpyS(temp, sizeof(GattBatteryInformation), &batteryInformation.batteryCriticalEnergy, 2 * sizeof(uint8));
                        temp += 2;
                    }
                    if (batteryInformation.batteryInformationFlags & BATTERY_CHEMISTRY_PRESENT) 
                    {
                        sizeValue += 1;
                        SynMemCpyS(temp, sizeof(GattBatteryInformation), &batteryInformation.batteryChemistry, sizeof(uint8));
                        temp += 1;
                    }
                    if (batteryInformation.batteryInformationFlags & NOMINAL_VOLTAGE_PRESENT) 
                    {
                        sizeValue += 2;
                        SynMemCpyS(temp, sizeof(GattBatteryInformation), &batteryInformation.nominalVoltage, 2 * sizeof(uint8));
                        temp += 2;
                    }
                    if (batteryInformation.batteryInformationFlags & BATTERY_AGGREGATION_GROUP_PRESENT) 
                    {
                        sizeValue += 1;
                        SynMemCpyS(temp, sizeof(GattBatteryInformation), &batteryInformation.batteryAggregationGroup, sizeof(uint8));
                        temp += 1;
                    }
                    CsrBtGattIndicationEventReqSend(batteryServer->gattId, cids[index], HANDLE_BATTERY_INFORMATION, sizeValue, (uint8*)value);
                }
            }
        }
        else
        {
            result = FALSE;
        }
    }
    return result;
}

/****************************************************************************/
bool GattBatteryServerSendManufacturerNameStringIndication(const GBASS* batteryServer, uint16 numberCids, const uint32* cids, uint8* manufacturerNameString)
{
    bool result = FALSE;
    uint16 index = 0;
    CSR_UNUSED(manufacturerNameString);
    if (batteryServer != NULL && manufacturerNameString != NULL)
    {
        if (batteryServer->indicationsEnabled)
        {
            result = TRUE;
            for (index = 0; index < numberCids; index++)
            {
                if (cids[index] == 0)
                {
                    /* CID must be non-zero */
                    result = FALSE;
                }
                else
                {
                    /* Send indication */
                    uint8* value = (uint8*)CsrPmemAlloc(100 * sizeof(uint8));
                    uint8* temp = value;
					uint16 sizeValue = 0;
                    while (*manufacturerNameString != '\0') 
                    {
                        SynMemCpyS(temp, 100, manufacturerNameString, sizeof(uint8));
                        manufacturerNameString++;
                        temp++;
                        sizeValue++;
                    }
                    CsrBtGattIndicationEventReqSend(batteryServer->gattId, cids[index], HANDLE_MANUFACTURER_NAME_STRING, sizeValue, value);
                }
            }
        }
        else
        {
            result = FALSE;
        }
    }
    return result;
}

/****************************************************************************/
bool GattBatteryServerSendModelNumberStringIndication(const GBASS* batteryServer, uint16 numberCids, const uint32* cids, uint8* modelNumberString)
{
    bool result = FALSE;
    uint16 index = 0;
    CSR_UNUSED(modelNumberString);
    if (batteryServer != NULL && modelNumberString != NULL)
    {
        if (batteryServer->indicationsEnabled)
        {
            result = TRUE;
            for (index = 0; index < numberCids; index++)
            {
                if (cids[index] == 0)
                {
                    /* CID must be non-zero */
                    result = FALSE;
                }
                else
                {
                    /* Send indication */
                    uint8* value = (uint8*)CsrPmemAlloc(100 * sizeof(uint8));
                    uint8* temp = value;
					uint16 sizeValue = 0;
                    while (*modelNumberString != '\0') {
                        SynMemCpyS(temp, 100, modelNumberString, sizeof(uint8));
                        modelNumberString++;
                        temp++;
                        sizeValue++;
                    }
                    CsrBtGattIndicationEventReqSend(batteryServer->gattId, cids[index], HANDLE_MODEL_NUMBER_STRING, sizeValue, value);
                }
            }
        }
        else
        {
            result = FALSE;
        }
    }
    return result;
}

/******************************************************************************/
bool GattBatteryServerSendSerialNumberIndication(const GBASS* batteryServer, uint16 numberCids, const uint32* cids, uint8* serialNumber, uint16 size)
{
    bool result = FALSE;
    uint16 index = 0;
    CSR_UNUSED(batteryServer);
    if ((batteryServer != NULL) && numberCids)
    {
        if (batteryServer->indicationsEnabled)
        {
            result = TRUE;
            for (index = 0; index < numberCids; index++)
            {
                if (cids[index] == 0)
                {
                    /* CID must be non-zero */
                    result = FALSE;
                }
                else
                {
                    /* Send Indication */
                    uint8* value = (uint8*)CsrPmemAlloc(size);
                    SynMemCpyS(value, size, serialNumber, size);
                    CsrBtGattIndicationEventReqSend(batteryServer->gattId, cids[index], HANDLE_SERIAL_NUMBER_STRING, size, value);
                }
            }
        }
        else
        {
            result = FALSE;
        }
    }
    return result;
}

#endif /* EXCLUDE_GATT_BATTERY_SERVICE_V1P1 */
